<template>
  <Tabs :animated="false">
    <TabPane label="虹软SDK">
      <Row>
        <Col span="22" push="1" pull="1">
          <Form ref="aiconfig" :model="aiconfig" :label-width="100">
            <FormItem prop="AppID" label="AppID" :rules="{required: true, message: '请输入AppID'}">
              <Input type="text" v-model="aiconfig.AppID" placeholder="请输入AppID"></Input>
            </FormItem>
            <FormItem prop="FT_key" label="人脸追踪(FT)" :rules="{required: true, message: '请输入FT_key'}">
              <Input type="text" v-model="aiconfig.FT_key" placeholder="请输入FT_key"></Input>
            </FormItem>
            <FormItem prop="FD_key" label="人脸检测(FD)" :rules="{required: true, message: '请输入FD_key'}">
              <Input type="text" v-model="aiconfig.FD_key" placeholder="请输入FD_key"></Input>
            </FormItem>
            <FormItem prop="FR_key" label="人脸识别(FR)" :rules="{required: true, message: '请输入FR_key'}">
              <Input type="text" v-model="aiconfig.FR_key" placeholder="请输入FR_key"></Input>
            </FormItem>
            <FormItem>
              <Button type="primary" @click="handleSubmit('aiconfig')">保存</Button>
            </FormItem>
          </Form>
          <Alert show-icon closable>
            注意事项：
            <template slot="desc">
              <p>1、在虹软官网申请AppID和KEY</p>
              <p>2、所有设置重启软件后生效</p>
            </template>
          </Alert>
        </Col>
      </Row>
    </TabPane>
    <TabPane label="软件设置">
      <Row>
        <Col span="22" push="1" pull="1">
          <Form ref="softconfig" :model="softconfig" :label-width="100">
            <FormItem prop="data_ptah" label="数据库路径" :rules="{required: true, message: '请输入数据库路径'}">
              <Input type="text" v-model="softconfig.data_ptah" placeholder="请输入数据库路径"></Input>
            </FormItem>
            <FormItem prop="face_dat_path" label="特征库路径" :rules="{required: true, message: '请输入特征库路径'}">
              <Input type="text" v-model="softconfig.face_dat_path" placeholder="请输入特征库路径"></Input>
            </FormItem>
            <FormItem prop="face_img_path" label="照片路径" :rules="{required: true, message: '请输入照片路径'}">
              <Input type="text" v-model="softconfig.face_img_path" placeholder="请输入照片路径"></Input>
            </FormItem>
            <FormItem prop="face_img_path" label="识别门限" :rules="{required: true, message: '请输入识别门限'}">
              <i-input type="text" v-model="softconfig.threshold" placeholder="请输入识别门限">
                <span slot="append">识别门限（取值范围：0-100）越低，通过率越高！</span>
              </i-input>
            </FormItem>
            <FormItem prop="face_img_path" label="时间间隔" :rules="{required: true, message: '请输入时间间隔'}">
              <i-input type="text" v-model="softconfig.interval" placeholder="请输入时间间隔">
                <span slot="append">同一人几秒后可再次被识别到，单位秒</span>
              </i-input>
            </FormItem>
            <FormItem>
              <Button type="primary" @click="handleSubmit('softconfig')">保存</Button>
            </FormItem>
          </Form>
          <Alert show-icon closable>
            注意事项：
            <template slot="desc">
              <p>1、填写正确的文件路径</p>
              <p>2、确保文件路径已经存在，不存请手动创建</p>
              <p>3、文件路径严格区分大小写</p>
              <p>4、文件路径以斜杠（\）结尾</p>
              <p>5、所有设置重启软件后生效</p>
            </template>
          </Alert>
        </Col>
      </Row>
    </TabPane>
  </Tabs>
</template>

<script>
  import {config} from '@/common/utils'

  export default {
    name: 'setup',
    created() {
      this.$store.commit('updateStatusMsg', '读取系统配置...')
      this.aiconfig = config.get('aiconfig')
      this.softconfig = config.get('softconfig')
    },
    methods: {
      handleSubmit(name) {
        this.$refs[name].validate((valid) => {
          if (valid) {
            config.set(name, this[name])
            this.$Message.success('设置成功，软件重启生效！')
          }
        })
      }
    },
    mounted() {
      this.$store.commit('updateStatusMsg', '')
    }
  }
</script>

<style scoped>

</style>